'use strict';

const Controller = require('egg').Controller;

class DirectorController extends Controller {
    // // 查询获取数据用控制器——GET——/name?keywords=?&&.....
    async get_topic() {
        const { ctx } = this;
        const keywords = ctx.query.keywords ? ctx.query.keywords : '';
        const pageIndex = ctx.query.pageIndex ? +ctx.query.pageIndex : 1;
        const pageSize = ctx.query.pageSize ? +ctx.query.pageSize : 5;
        console.log('keywords', keywords);
        const result = await ctx.service.topic.findNotPass(keywords, pageIndex, pageSize);
        ctx.status = 200;
        ctx.body = result;
    }
    async topic_pass(){
        const { ctx } = this;
        const topic_id = ctx.params.id;
        console.log('topic_id:::',topic_id);
        const result = await ctx.service.topic.modify({id:topic_id,pass:2});
        ctx.body = result;
    }
    async topic_not_pass(){
        const { ctx } = this;
        const { ins_id, content, dir_id ,topic_id} = ctx.request.body;
        const msg = {
            ins_id,
            content,
            dir_id,
            topic_id
        }
        const result = await ctx.service.dirinsmsg.add(msg);
        const result2 = await ctx.service.topic.modify({
            id:msg.topic_id,
            pass:1
        });
        
        ctx.status = 201;
        ctx.body = result;
        return result;
    }
    // 查看个人信息使用看老师信息的show方法
}
module.exports = DirectorController;
